﻿using IBLL;
using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    public class MemberBLL:IMemberBLL
    {
        public MemberBLL(IBaseDAL<Member> dal)
        {
            Dal = dal;
        }

        public IBaseDAL<Member> Dal { get; }

        public async Task<int> AddMember(Member member)
        {
            return await Dal.AddAsync(member);
        }

        public async Task<int> DeleteMember(int id)
        {
            var m= Dal.GetAllAsync().FirstOrDefault(x=>x.Id == id);
            return await Dal.DeleteAsync(m);
        }

        public Member FindMember(int id)
        {
            return Dal.GetAllAsync().FirstOrDefault(x => x.Id.Equals(id));
        }

        public List<Member> GetAllMembers()
        {
            return Dal.GetAllAsync().ToList();
        }

        public Task<int> IsDel(int id)
        {
            var m = Dal.GetAllAsync().FirstOrDefault(x => x.Id == id);
            m.IsDel=true;
            m.DeleteTime=DateTime.Now;
            return Dal.UpdateAsync(m);
        }

        public Task<int> UpdateMember(Member member)
        {
            member.UpdateTime=DateTime.Now;
            return Dal.UpdateAsync(member);
        }
    }
}
